import matplotlib.pyplot as plt
import numpy as np


def thermostat_tank_state_chart():
    # 模拟时间范围（这里简单以离散的时间点表示，可根据实际需求细化）
    time = np.arange(0, 24 * 60 * 60, 60)  # 以分钟为间隔，模拟一天的时间

    temperature = np.zeros_like(time)
    power_status = np.zeros_like(time)
    repair_status = np.zeros_like(time)

    water_level = True  # 假设初始水箱有水，可根据实际水量传感器数据更新

    for i, t in enumerate(time):
        hour = t // (60 * 60)
        minute = (t % (60 * 60)) // 60

        if hour == 23 and minute == 0:  # 晚上11点整
            power_status[i] = 0  # 断开电源，进入休眠
        elif hour == 7 and minute == 0:  # 早上7点整
            power_status[i] = 1 if water_level and temperature[i - 1] < 20 else 0

        if power_status[i] == 1:
            temperature[i] = min(temperature[i - 1] + 1, 100) if temperature[i - 1] < 100 else 100
            if temperature[i] >= 100:
                power_status[i] = 0
        elif power_status[i] == 0 and water_level and temperature[i - 1] < 20:
            power_status[i] = 1

        if temperature[i] > 100:  # 假设水箱温度超过100度视为水箱烧坏
            repair_status[i] = 1

    plt.plot(time, temperature, label='Temperature')
    plt.plot(time, power_status * 100, label='Power Status (On: 100, Off: 0)')
    plt.plot(time, repair_status * 200, label='Repair Status (Needs Repair: 200, OK: 0)')

    plt.xlabel('Time (seconds)')
    plt.ylabel('Status')
    plt.title('Thermostat Tank State Chart')
    plt.legend()
    plt.show()